﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="DatabasesClear.aspx.cs" Inherits="DatabasesClear" %>

<asp:Content ClientIDMode="Static" runat="server" ContentPlaceHolderID="BodyContent">
    <div class="contentfull">
        <div class="breadcrumbs">
            <ul id="crumbs">
                <li><a title="My Account" href="#">My Account</a>
                    <img src="Content/Images/separator.png" alt="&rarr;" class="separator">
                    Rosters 			</li>
            </ul>
        </div>

        <div id="showMessages" runat="server" visible="false">
            <div class='success'>
                <p></p>
                <li>
                    <span id="mmsg" runat="server"></span>
                </li>
                <p></p>
            </div>
        </div>


        <div class="top">
            <div class="innerleft">
                <h1>
                    <img src="Images/database-icon.png" width="32px" height="32px" alt="Database">
                    <span id="databaseName"><% =GetDatabaseName() %></span>
                    <form id="renameform">
                        <input type="hidden" name="action" value="renamedb" />
                        <input type="hidden" id="hdnUserId" name="hdnUserId" value="<% =GetUserId() %>" />
                        <input type="hidden" name="listid" id="listid" value="<% =GetDatabaseId() %>" />
                        <input type="text" class="inputed" id="dbname" name="dbname" value="<% =GetDatabaseName() %>" />
                        <input type="submit" id="rename-button" value="Rename" />
                    </form>
                    <a id="rename1" title="Click to rename">Rename</a>
                </h1>
                <span class="db_value"><% =GetCaseSensitiveCount() %></span>
                <script type="text/javascript">
                    $(document).ready(function () {
                        var messengerDiv = $("div#showMessages");
                        $("#rename1").click(function (event) {
                            $('#databaseName').hide();
                            $("#rename1").hide();
                            $("#renameform").show().css("display", "inline");
                            return false;
                        });

                        $("#dbname").click(function (event) {
                            return false;
                        });

                        $("#renameform").submit(function (event) {
                            var _data = '<?xml version="1.0" encoding="utf-8"?>' +
                                            '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">' +
                                            '<soap:Body>' +
                                                '<RenameDatabase xmlns="http://tempuri.org/">' +
                                                    ' <dbId>' + $("input#listid").val() + '</dbId>' +
                                                    '<newDBName>' + $("input#dbname").val() + '</newDBName>' +
                                                    ' <loggedInUserId>' + $("input#hdnUserId").val() + '</loggedInUserId>' +
                                                    '</RenameDatabase>' +
                                                '</soap:Body>' +
                                           '</soap:Envelope>';
                            // alert(_data);
                            $.ajax({
                                type: "POST",
                                url: "http://ssica.org/services/CommonService.asmx?op=RenameDatabase",
                                data: _data,
                                contentType: "text/xml;charset-uf8",
                                dataType: "xml",
                                success: function (msg) {
                                    var result = $("RenameDatabaseResult", msg);
                                    var res = $(result).text();
                                    // alert(res);
                                    if (res != 'error') {
                                        $("#renameform").hide();
                                        $("#databaseName").fadeIn().html(res);
                                        $("#dbname").val(res);
                                        messengerDiv.removeClass().addClass("success");
                                        var showMessage = 'Roster has been renamed.';
                                        if (messengerDiv.is(":empty")) {
                                            messengerDiv.empty().append("<p></p>").append("<li>" + showMessage + "</li>").hide().slideDown();
                                        } else {
                                            messengerDiv.hide().empty().append("<p></p>").append("<li>" + showMessage + "</li>").fadeIn();
                                        }
                                    } else {
                                        messengerDiv.removeClass().addClass("warning");
                                        var showMessage = 'Database could not be renamed. Certain special characters are not allowed.';
                                        if (messengerDiv.is(":empty")) {
                                            messengerDiv.empty().append("<p></p>").append("<li>" + showMessage + "</li>").hide().slideDown();
                                        } else {
                                            messengerDiv.hide().empty().append("<p></p>").append("<li>" + showMessage + "</li>").fadeIn();
                                        }
                                    }

                                }
                            });
                            return false;
                        });

                        $("body").not("#renameform").click(function (event) {
                            if ($("#renameform").is(':visible')) {
                                $("#renameform").fadeOut();
                                $("#databaseName").delay(400).fadeIn();
                                $("#rename1").delay(400).fadeIn();
                            }
                        });

                    });
                </script>
            </div>
        </div>
        <div class="content">
            <div class="tabs_box">
                <ul id="tabs">
                    <li><a class="tabs_off" href="DatabaseSearch.aspx?dbid=<% =GetDatabaseId() %>&mode=Edit">Search</a></li>
                    <li><a class="tabs_off" href="DatabasesAddValue.aspx?dbid=<% =GetDatabaseId() %>&mode=edit">Add</a></li>
                    <li><a class="tabs_off" href="DatabasesImport.aspx?dbid=<% =GetDatabaseId() %>&mode=edit">Import</a></li>
                    <li><a class="tabs_off" href="DatabasesExport.aspx?dbid=<% =GetDatabaseId() %>&mode=edit">Export</a></li>
                   <%-- <li><a class="tabs_off" href="DatabasesAutofill.aspx?dbid=<% =GetDatabaseId() %>&mode=edit">Autofill</a></li>--%>
                    <li><a class="tabs_on" href="#">Clear</a></li>
                </ul>
            </div>
            <fieldset>
                <div class="import_left">
                    <h2>Clear your Roster</h2>
                    <label>Pressing the button below will delete all values from this Roster. This action has no undo.</label>
                    <p><a href="#" onclick="$('#btnExport').trigger('click');" class="black_button blink">Empty Roster</a></p>

                </div>
            </fieldset>
            <div style="clear: both;"></div>
        </div>

    </div>
    <form runat="server">
        <asp:Button ID="btnExport" runat="server" ClientIDMode="Static" Text="" OnClick="btnExport_Click" Style="visibility: hidden; width: 0px" />
    </form>
</asp:Content>